﻿/*10.Write a program that finds in given array of integers a sequence of given sum S (if present).
 * Example:	 {4, 3, 1, 4, 2, 5, 8}, S=11  {4, 2, 5} */

using System;

    class SumInArray
    {
        static void Main()
        {
            int startPosition=0;
            int endPosition=0;
            int tempSum = 0;
            Console.Write("Sum= ");
            int sum = int.Parse(Console.ReadLine());
            Console.Write("Size of the array= ");
            int size = int.Parse(Console.ReadLine());
            int [] array = new int[size];
            //reading the array
            for (int i = 0; i < array.Length; i++)
            {
                Console.Write("Element[{0}]=",i);
                array[i] = int.Parse(Console.ReadLine());
            }
            for (int j = 0; j < array.Length; j++)
            {
                for (int k = j; k < array.Length; k++)
                {
                    tempSum += array[k];
                    if (tempSum==sum)
                    {
                        startPosition = j;
                        endPosition = k;
                    }                   
                }
                tempSum = 0;
            }
            Console.Write("{");
            for (int i = startPosition; i <= endPosition; i++)
            {
                Console.Write(array[i] + ((i != endPosition) ? "," : ""));
            }
            Console.WriteLine("}");
        }
    }

